<?php
require_once('../classes/smarty_setup.php');
require_once('../classes/mofachi.User.php');
$smarty = new Smarty_mofachi();

@ $act = $_REQUEST[ "act" ];
if( $act == "add" ) {
	addUserinfo();
} else if( $act == "remove" ) {
	removeUserinfo();
} else if( $act == "get" ) {
	getUserinfo( $smarty );
} else if( $act == "update" ) {
	updateUserinfo();
}
$smarty->assign( 'act', $act );

listUserinfo( $smarty );
$smarty->display('t02_userinfo.htm');

function listUserinfo( $smarty ) {
	$result = User::listUserInfo( 0, 20 );
	$smarty->assign( 'res', $result );
}
function addUserinfo() {
	@ $user_id = $_REQUEST[ 'uid' ];
	@ $nickname = $_POST[ 'nickname' ];
	@ $realname = $_POST[ 'realname' ];
	@ $gender = $_POST[ 'gender' ];
	@ $location_id = $_POST[ 'location_id' ];
	@ $birthday = $_POST[ 'birthday' ];
	if( !$user_id || !$nickname )
		return;
	
	$user = new User();
	$user->user_id = $user_id;
	$user->nickname = $nickname;
	$user->realname = $realname;
	$user->gender = $gender;
	$user->location_id = $location_id;
	$user->birthday = $birthday;
	$user->addInfo();
}
function removeUserinfo() {
	@ $delist = $_POST[ "delist" ];
	if( !$delist )
		return;

	$id_array = explode( ",", $delist );
	foreach( $id_array as $key => $value ) {
		$user = new User();
		$user->user_id = $value;
		$user->remove();
	}
}
function getUserinfo( $smarty ) {	
	@ $uid = $_GET[ "uid" ];
	if( !$uid )
		return;
	
	$user = new User();
	$user->user_id = $uid;
	$user->loadInfoById();
	$smarty->assign( 'row', $user );
}
function updateUserinfo() {
	@ $uid = $_POST[ 'uid' ];
	@ $nickname = $_POST[ 'nickname' ];
	@ $realname = $_POST[ 'realname' ];
	@ $gender = $_POST[ 'gender' ];
	@ $location_id = $_POST[ 'location_id' ];
	@ $birthday = $_POST[ 'birthday' ];

	if( !$uid || !$nickname )
		return;
	
	$user = new User();
	$user->user_id = $uid;
	$user->loadInfoById();
	$user->nickname = $nickname;
	$user->realname = $realname;
	$user->gender = $gender;
	$user->location_id = $location_id;
	$user->birthday = $birthday;
	$user->updateInfo();
}
?>